﻿@using QH.JobBack.Model;
@{
    var modulist = ViewBag.modulist as List<Module>;

    var parentMenu = ViewBag.parentMenu as List<MenuInfo>;
}
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>添加管理员 - 统一权限管理平台</title>
    <link rel="stylesheet" href="~/static/common/layui/css/layui.css">
    <link rel="stylesheet" href="~/static/admin/css/style.css">
    <script src="~/static/common/layui/layui.js"></script>
    <script src="~/static/common/jquery-3.3.1.min.js"></script>
    <script src="~/static/common/vue.min.js"></script>
</head>
<body>
    <div id="app">
        

        <div class="main" id="app">
            
            <!--右侧-->
            <div class="">
                <fieldset class="layui-elem-field layui-field-title">
                    <legend>添加组</legend>
                </fieldset>
                <form class="layui-form " action="/Menu/SaveMenu" method="post">
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属组</label>
                        <div class="layui-input-inline">
                            <select name="ModuleId" lay-verify="required">
                                @foreach (var item in modulist)
                                {
                                    <option value=@item.Id>@item.Name</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">上级菜单</label>
                        <div class="layui-input-inline">
                            <select name="ParentId" lay-verify="required">
                                <option value="0">请选择</option>
                                @foreach (var item in parentMenu)
                                {
                                    <option value=@item.MenuId>@item.MenuName</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">菜单名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="MenuName" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">菜单地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="Url" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">菜单图标</label>
                        <div class="layui-input-block">
                            <input type="text" name="Ico" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否显示</label>
                        <div class="layui-input-block">
                            <input type="checkbox" value="true" name="Status" lay-text="开启|关闭" checked lay-skin="switch" lay-filter="swtichShow">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="submit" onclick="return false;">立即提交</button>
                        </div>
                    </div>
                </form>

            </div>
        </div>
    </div>
    <script src="~/static/admin/js/script.js"></script>
    <script>
        $(function () {
            layui.use('form', function () {
                var form = layui.form,
                    layer = layui.layer,
                    $ = layui.jquery;

                //监听是否显示开关
                form.on('switch(swtichShow)', function (data) {
                    var _this = $(this);
                    if (this.checked) {
                        _this.val('true')
                    }
                    else {
                        _this.val('false')
                    }
                });

                //表单提交
                form.on('submit(submit)', function (data) {
                    $.ajax({
                        url: '/Menu/AddMenu',
                        method: 'post',
                        data: data.field,
                        dataType: 'JSON',
                        success: function (res) {
                            if (res.success) {
                                layer.msg(res.msg, {
                                    title: '提示框',
                                    icon: 1,
                                    time: 3000,
                                    end: function () {
                                        window.location.href = '/Menu/Index';
                                    }
                                });
                            }
                            else {
                                layer.alert(res.msg);
                                return false;
                            }
                        },
                        error: function (data) {

                        }
                    });
                });
            });
        });
    </script>
</body>
</html>
